<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>创建并验证节点</title>
</head>
<script type="text/javascript" src="node.js"></script>
<script type="text/javascript">
/*    function nodeStatus(node) {
        var temp = "";
        if(node!=null) {
            temp += "nodeName:" + node.nodeName + "\n";
        }
        else temp += "nodeName:null!\n";
        if(node.nodeType!=null) {
            temp += "nodeType:" + node.nodeType + "\n";
        }
        else temp += "nodeType:null!\n";
        if(node.nodeValue!=null) {
            temp += "nodeValue:" + node.nodeValue + "\n";
        }
        else temp += "nodeValue:null!\n";
        return temp;
    }*/

    function MyTest() {
        //产生p元素节点和新文本节点
        var newParagraph = document.createElement("p");
        var newTextNode = document.createTextNode(document.MyForm.MyField.value);
        newParagraph.appendChild(newTextNode);
        var msg = nodeStatus(newParagraph);
        msg += nodeStatus(newTextNode);
        msg += nodeStatus(newParagraph.firstChild);
        alert(msg);
    }
</script>
<body>
<form name="MyForm">
    <input type="text" name="MyField" value="Text">
    <input type="button" value="test" onclick="MyTest()">

</form>

</body>
</html>